package Lab08;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class Ex8_5 {
    public static void main(String[] args) {

        Account account = new Account(1112, "George", 1000);
        account.setAnnualInterestRate(1.5);
        account.deposit(30);
        account.deposit(40);
        account.deposit(50);

        account.withdraw(5);
        account.withdraw(4);
        account.withdraw(2);
        System.out.println("Name: " + account.getName());
        System.out.println("Annual Interest Rat: " + account.getAnnualInterestRate());
        System.out.println("Balance: " + account.getBalance());

////        System.out.println("Date\t\t\t\t\t\t\tType\tAmount\tBalance");
        System.out.println("Type   Amount   Balance");
//        for(Transaction transaction:account.getTransactions()){
//            System.out.println(transaction.getDate()+"\t"+transaction.getType()+"\t\t"+
//                    String.format("%4.1f",transaction.getAmount())+"\t"+transaction.getBalance());
//        }

        for (Transaction transaction : account.getTransactions()) {
            System.out.println(transaction.getType() + "   " +
                    transaction.getAmount() + "   " + transaction.getBalance());
        }
    }
}

class Transaction {
    private Date date;
    private char type;
    private double amount;
    private double balance;
    //    余额
    private String description;

    public Date getDate() {
        return date;
    }

    public char getType() {
        return type;
    }

    public double getAmount() {
        return amount;
    }

    public double getBalance() {
        return balance;
    }

    public String getDescription() {
        return description;
    }

    public Transaction(char type, double amount, double balance, String description) {
        this.date = new Date();
        this.type = type;
        this.amount = amount;
        this.balance = balance;
        this.description = description;
    }
}

class Account {
    private int id;
    private String name;
    private double balance;
    private double annualInterestRate;
    private Date dateCreated;
    private ArrayList<Transaction> transactions = new ArrayList<>();

    public void deposit(double amount) {
        balance += amount;
        String description = "deposit: " + amount;
        transactions.add(new Transaction('D', amount, balance, description));
    }

    public void withdraw(double amount) {
        balance -= amount;
        String description = "withdraw: " + amount;
        transactions.add(new Transaction('W', amount, balance, description));
    }

    public double getMonthlyInterest() {
        return balance * annualInterestRate / 12;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public double getBalance() {
        return balance;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }


    public List<Transaction> getTransactions() {
        return transactions;
    }


    public Account() {
    }

    public Account(int id, String name, double balance) {
        this.id = id;
        this.name = name;
        this.balance = balance;
        this.dateCreated = new Date();
    }
}
